﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Xml;
using System.ServiceModel;
using System.ServiceModel.Activation;

namespace PosrednikStoritev
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Posrednik : IPosrednik
    {
        public string[] Sinf_StukProg()
        {
            XmlDocument xmlDocument = new XmlDocument(); 
            Sinf_StukProg.cir2012SiNf_StukProg ssp = new Sinf_StukProg.cir2012SiNf_StukProg();
            XmlNode[] vrniProgram = (XmlNode[])ssp.vrniProgramDogajanja().@return;
            string[] poljeVnosov=new string[vrniProgram[5].ChildNodes.Count];
            int stevec=0;
            foreach(XmlNode node in vrniProgram[5].ChildNodes)
            {
                poljeVnosov[stevec] = node.InnerText;
                stevec++;
            }
            return poljeVnosov;
        }

        public string[] Sinf_UMNews()
        {
            Sinf_UMNews.cir2012SiNf_UMNews sumn = new PosrednikStoritev.Sinf_UMNews.cir2012SiNf_UMNews();
            XmlNode[] vrniNovice = (XmlNode[])sumn.SiNf_UMNews().@return;
            string[] poljeVnosov = new string[vrniNovice.Length-5];
            int stevec = 0;
            foreach (XmlNode node in vrniNovice)
            {
                if (stevec >= 5)
                {
                    poljeVnosov[stevec - 5] = node.InnerText;
                }
                stevec++;
            }
            return poljeVnosov;
        }

        public string[] Sinf_Vreme(string mesto)
        {
            Sinf_Vreme.cir2012SiNf_Vreme sv = new PosrednikStoritev.Sinf_Vreme.cir2012SiNf_Vreme();
            XmlNode[] vrniVreme = (XmlNode[])sv.vrniVremeZaMesto(mesto);
            string[] poljeVnosov = new string[21];
            int stevec = 0;
            int stevec2 = 0;
            foreach (XmlNode trenutno in vrniVreme[5].ChildNodes[1])
            {
                if (stevec % 2 == 1)
                {
                    poljeVnosov[stevec2] = trenutno.InnerText;
                    stevec2++;
                }
                stevec++;
            }
            int stevec3 = 0;
            int stevec4 = 1;
            foreach (XmlNode napovedDan in vrniVreme[5].ChildNodes[3])
            {
                if (stevec3 % 2 == 1)
                {
                    poljeVnosov[stevec2] = napovedDan.Attributes[0].Value;
                    stevec2++;
                    foreach (XmlNode ostali in vrniVreme[5].ChildNodes[3].ChildNodes[stevec4])
                    {
                        if (ostali.Name=="razmere")
                        {
                            poljeVnosov[stevec2] = ostali.InnerText;
                            stevec2++;
                        }
                        else if (ostali.Name == "najnizja_temperatura")
                        {
                            poljeVnosov[stevec2] = ostali.InnerText;
                            stevec2++;
                        }
                        else if (ostali.Name == "najvisja_temperatura")
                        {
                            poljeVnosov[stevec2] = ostali.InnerText;
                            stevec2++;
                        }
                        else if (ostali.Name == "slika")
                        {
                            poljeVnosov[stevec2] = ostali.InnerText;
                            stevec2++;
                            stevec4 = stevec4 + 2;
                        }
                    }                 
                }               
                stevec3++;
            }
            return poljeVnosov;
        }

        public string[] Sinf_SoumNews()
        {
            Sinf_SoumNews.cir2012SiNf_SoumNews ssn = new PosrednikStoritev.Sinf_SoumNews.cir2012SiNf_SoumNews();
            XmlNode[] vrniNovice = (XmlNode[])ssn.vrniSoumNovice().@return;
            string[] poljeVnosov = new string[vrniNovice[5].ChildNodes.Count];
            int stevec = 0;
            foreach (XmlNode node in vrniNovice[5])
            {
                poljeVnosov[stevec] = node.InnerText;
                stevec++;
            }
            return poljeVnosov;
        }

        public string[] Sinf_FeriNews()
        {
            Sinf_FeriNews.cir2012SiNf_FeriNews sfn = new PosrednikStoritev.Sinf_FeriNews.cir2012SiNf_FeriNews();
            XmlNode[] vrniNovice = (XmlNode[])sfn.feriNovice().@return;
            string[] poljeVnosov = new string[vrniNovice[5].ChildNodes.Count-2];
            int stevec = 0;
            foreach (XmlNode node in vrniNovice[5])
            {
                if (node.Name == "obvestilo")
                {
                    poljeVnosov[stevec] = node.InnerText;
                    stevec++;
                }          
            }
            return poljeVnosov;
        }

        public string[] Sinf_FeriForum()
        {
            Sinf_FeriForum.cir2012SiNf_FeriForum sff = new PosrednikStoritev.Sinf_FeriForum.cir2012SiNf_FeriForum();
            XmlNode[] vrniNovice = (XmlNode[])sff.vrniZadnjeForum().@return;
            string[] poljeVnosov = new string[vrniNovice[5].ChildNodes.Count];
            int stevec = 0;
            foreach (XmlNode node in vrniNovice[5])
            {
                poljeVnosov[stevec] = node.InnerText;
                stevec++;
            }
            return poljeVnosov;
        }

        public string[] Sinf_FeriZagovori()
        {
            Sinf_FeriZagovori.cir2012FeriZagovori sfz = new PosrednikStoritev.Sinf_FeriZagovori.cir2012FeriZagovori();
            XmlNode[] vrniNovice = (XmlNode[])sfz.FeriZagovori().@return;
            List<string> poljeVnosov = new List<string>();
            foreach (XmlNode node in vrniNovice[5])
            {
                if (node.Name == "Zagovor")
                {
                    foreach (XmlNode posamezen in node.ChildNodes)
                    {
                        if (posamezen.Name == "ImeKandidata")
                        {
                            poljeVnosov.Add(posamezen.InnerText);
                        }
                        else if (posamezen.Name == "NaslovDiplomskegaDela")
                        {
                            poljeVnosov.Add(posamezen.InnerText);
                        }
                        else if (posamezen.Name == "DatumInMestoZagovora")
                        {
                            poljeVnosov.Add(posamezen.InnerText);
                        }
                    }
                }
            }
            string[] polje = new string[poljeVnosov.Count];
            int stevec = 0;
            foreach (string element in poljeVnosov)
            {
                polje[stevec] = poljeVnosov[stevec];
                stevec++;
            }
            return polje;
        }
    }
}
